<?

if ($DATA['component']['id']) {

	// list editor
	
	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_param			= 'slide';				//	ID param name in the URL, used here & @ template
	$_multilang			= array('text');	// which fields are stored in language variations
	$_singlelang		= array('title', 'video', 'kind');	// which fields are stored without language variations
	

	$s = array_extend( array(
		'path' => 'project', 'w' => 128, 'h' => 96, 'param' => 'id', 'sw' => 640, 'sh' => 390
	), $DATA['component']['settings']);

	$e = (int)param('edit');
	
	$_crit = "id_data=$_id_data AND id_parent=$e";

	
	if ($e && ($a = (int)param($_param)) && ($DATA['object'] = datafetch('db_item', tb('data'), "$_crit AND id=$a"))) {

		$s['path'] = createdir(FP_UPLOAD_PATH."$s[path]/$e/");

		$_crit = "id_data=$_id_data AND id_parent=$e";

	
		switch (action(array('editor_save', 'editor_save_enable', 'create_object'))) {
		
			case 'editor_save_enable':
			
				$DATA['object']['attr'] |= AA_VISIBLE;
			
			case 'editor_save':

				$_record = array('id_data' => $_id_meta, 'id_parent' => $a);
				$temp = array();
	
				foreach($DATA['langs'] as $lang) {	// store multilanguage
					foreach($_multilang as $name) {
						$t = postdata($name);
						$temp[] = array_merge($_record, array('id_parent' => $a, 'name' => $name, 'value' => $t[$lang['text']], 'assoc' => $lang['text']));
					}
				}

				foreach($_singlelang as $name)	// store language independent
					$temp[] = array_merge($_record, array('id_parent' => $a, 'name' => $name, 'value' => postdata($name), 'assoc' => ''));

				dataset('db_delete', tb('data'), "id_data=$_id_meta AND id_parent=$a");
				dataset('db_insert', tb('data'), $temp);

				dataset('db_update', tb('data'), array('name' => trim(postdata('title')), 'attr' => $DATA['object']['attr']), "id=$a");

				takeImage('image', $s['sw'], $s['sh'], "$s[path]$a");

				header("Location: "._transformURL($CURRENT->url, array('remove_param' => $_param)));
				exit;
		
				break;
		}
	
	
	
		
		$DATA['object'] = array_merge($DATA['object'], datafetch_array('meta', $_id_meta, $a));

		foreach($DATA['langs'] as $lang)
			$DATA['object']['data'][$lang['text']] = datafetch_array('meta', $_id_meta, $a, $lang['text']);
			
		$DATA['object']['image'] = checkImage($s['path'], $a);
	}
	


	return false;
	
} else exit;